<?php include _include(APP_PATH.'view/htm/header.inc.htm');?>

<div class="row">
	<div class="col-lg-6 mx-auto">
		<div class="card">
			<div class="card-header"><?php echo lang('user_resetpw');?></div>
			<!--{hook user_create_card_title.htm}-->
			<div class="card-body">
				<form action="<?php echo $form_action;?>" method="post" id="form">
					<div class="form-group input-group">
						<div class="input-group-prepend">
							<span class="input-group-text"><i class="icon icon-envelope icon-fw"></i></span>
						</div>
						<input type="text" class="form-control" placeholder="<?php echo lang('email');?>" name="email" id="email" value="<?php echo $email;?>" disabled>
					</div>
					<div class="form-group input-group">
						<div class="input-group-prepend">
							<span class="input-group-text"><i class="icon icon-lock icon-fw"></i></span>
						</div>
						<input type="password" class="form-control" placeholder="<?php echo lang('password_new');?>" id="password" name="password" required>
					</div>
					<div class="form-group input-group">
						<div class="input-group-prepend">
							<span class="input-group-text"><i class="icon icon-lock icon-fw"></i></span>
						</div>
						<input type="password" class="form-control" placeholder="<?php echo lang('password_new_repeat');?>" id="password2" required>
					</div>
					<p>
						<button type="submit" class="btn btn-primary btn-block" id="submit" data-loading-text="<?php echo lang('submiting');?>..." <?php echo $conf['user_create_email_on'] ? 'disabled' : '';?>>
						    <?php echo lang('next_step');?>
						</button>
					</p>
				</form>
			</div>
		</div>
	</div>
</div>

<?php include _include(APP_PATH.'view/htm/footer.inc.htm');?>
<script src="<?php echo view_path();?>js/md5.js"></script>
<script>
	var body = $('body');
	var jpassword = $('#password');
	var jpassword2 = $('#password2');
	body.on('submit', '#form', function () {
		var jthis = $(this);
		jthis.reset();
		var jsubmit = jthis.find('#submit');
		jsubmit.button('loading');

		if (!jpassword.val()) {
			jpassword.focus();
			$.alert('<?php echo lang('please_input_password');?>');
			jsubmit.button('reset');
			return false;
		}

		if (jpassword.val() != jpassword2.val()) {
			jpassword2.focus();
			$.alert('<?php echo lang('repeat_password_incorrect');?>');
			jsubmit.button('reset');
			return false;
		}

		var postdata = jthis.serializeObject();
		postdata.password = $.md5(postdata.password);
		$.xpost(jthis.attr('action'), postdata, function (code, message) {
			if (code == 0) {
				$.alert(message);
				jsubmit.button(message).delay(1000).location(xn.url('user-login'));
			} else if (xn.is_number(code)) {
				$.alert(message);
				jsubmit.button('reset');
			} else {
				jthis.find('[name="' + code + '"]').alert(message).focus();
				jsubmit.button('reset');
			}
		});
		return false;
	});
</script>